﻿@{
    ViewBag.Title = T("Admin.Configuration.QuantityUnit").Text;
}

<div class="section-header">
    <div class="title">
		<i class="fas fa-box-open"></i>
        <span>@T("Admin.Configuration.QuantityUnit")</span>
    </div>
</div>

<div>
	@(Html.Telerik().Grid<QuantityUnitModel>()
        .Name("quantity-unit-grid")
        .DataKeys(x =>
        {
            x.Add(y => y.Id);
        })
        .Columns(columns =>
        {
            columns.Bound(x => x.Name);
            columns.Bound(x => x.NamePlural)
                .Title(T("Common.Plural").Text);
            columns.Bound(x => x.Description)
                .Centered();
            columns.Bound(x => x.DisplayOrder)
                .Width(180)
                .Centered();
            columns.Bound(x => x.IsDefault)
                .ClientTemplate(Html.SymbolForBool("IsDefault"))
                .Width(180)
                .Centered();
            columns.Command(commands =>
            {
                commands.Custom("edit-quantity-unit").Text(T("Common.Edit"));
                commands.Delete().Localize(T);
            }).Width(180)
            .HtmlAttributes(new { align = "right", @class = "omega" });
        })
        .ToolBar(commands => commands.Template(QuantityUnitGridCommands))
		.DataBinding(dataBinding =>
		{
			dataBinding.Ajax()
                .Select("List", "QuantityUnit")
				.Delete("DeleteQuantityUnit", "QuantityUnit");
		})
		.EnableCustomBinding(true))
</div>

@helper QuantityUnitGridCommands(Grid<QuantityUnitModel> grid)
{
	<button type="submit" id="btnAddNew" name="btnAddNew" class="btn" onclick="javascript:openPopup('@(Url.Action("CreateQuantityUnitPopup", "QuantityUnit", new { btnId = "btnRefresh" }))'); return false;">
		<i class="fa fa-plus"></i>
		<span>@T("Admin.Configuration.QuantityUnit.AddQuantityUnit")</span>
	</button>
	<input type="submit" id="btnRefresh" name="btnRefresh" class="d-none" />
}

<script>
	$(function() {
		$('#btnRefresh').click(function () {
			$('#quantity-unit-grid').data('tGrid').ajaxRequest();
			return false;
		});

		$('#quantity-unit-grid').on('click', '.t-grid-edit-quantity-unit', function (e) {
			e.preventDefault();
			var tr = $(this).closest('tr');
			var id = $('#quantity-unit-grid').data('tGrid').dataItem(tr).Id;
			var href = "@Url.Content("~/Admin/QuantityUnit/EditQuantityUnitPopup/")" + id + "?btnId=btnRefresh";
			
			openPopup(href);
			return false;
		});
	});
</script>
